package com.example.demo.service;

import com.example.demo.model.User;
import com.example.demo.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserService {

    @Autowired
    private final UserRepository userRepository;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }


    public User getUserById(Long id) {
        return userRepository.findById(id).
                orElseThrow(() ->new RuntimeException("user not found "));
    }
    public User saveUser(User user) {
        return userRepository.save(user);
    }

    public void performSomeAction() {
        System.out.println("Performing some action");

        // Simulate a task by sleeping for a while
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
    }
}
